package com.group02.community.service.impl;


import com.alibaba.excel.EasyExcel;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.group02.community.entity.dict.SysDictData;
import com.group02.community.mapper.SysDictDataMapper;
import com.group02.community.service.SysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * <p>
 * 字典数据表 服务实现类
 * </p>
 *
 * @author xl
 * @since 2022-07-01
 */
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements SysDictDataService {

    @Autowired
    private SysDictDataMapper sysDictDataMapper;

    @Override
    public IPage<SysDictData> selectAllDictDatas(Long current, Long size, String dict_type, SysDictData sysDictData) {
        IPage<SysDictData> dictTypeIPage =sysDictDataMapper.selectAllDictData(new Page<SysDictData>(current,size),dict_type,sysDictData);
        return dictTypeIPage;
    }

    @Override
    public void deleteSelectDictData(String id) {
        sysDictDataMapper.deleteSelectDictData(id);
    }

    @Override
    public void downloadExcel(HttpServletResponse response) throws IOException {
        //查询所有数据
        List<SysDictData> sysDictData = sysDictDataMapper.selectList(null);
        //设置文件下载
        //设置响应头，告诉浏览器要以文件的形式保存
//        response.setHeader();
        response.setHeader("content-disposition","attachment;filename="+System.currentTimeMillis()+".xls");
        //生成Excel并写入
        EasyExcel.write(response.getOutputStream(),SysDictData.class).sheet(System.currentTimeMillis()+"").doWrite(sysDictData);
    }

    @Override
    public List<SysDictData> getAllRoomStatus() {
        return sysDictDataMapper.getAllRoomStatus();
    }

    @Override
    public List<SysDictData> getAllIsShop() {
        return sysDictDataMapper.getAllIsShop();
    }

    @Override
    public List<SysDictData> getAllRoomType() {
        return sysDictDataMapper.getAllRoomType();
    }

    @Override
    public List<SysDictData> getAllElevator() {
        return sysDictDataMapper.getAllElevator();
    }
}
